﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SM2TestRunner
{
    public class TestParameters
    {
        public string[,] parameters;

        public TestParameters()
        {
            parameters = new string[2,100];
        }

        public void add(string strkey, string strvalue)
        {
            for (int intColumn = 0; intColumn < 100; intColumn++)
            {
                // get current item of name 
                string strTempKey = parameters[0, intColumn];
                if (strTempKey == null)
                {
                    parameters[0, intColumn] = strkey;
                    parameters[1, intColumn] = strvalue;
                    break;
                }
            }
        }

        public string buildTestData()
        {
            string stParameters = "";
            for (int i = 0; i < 100; i++)
            {
                string strElementDetail = this.getItem(i);
                if (strElementDetail != null)
                {
                    stParameters += strElementDetail + "<br/>";
                }
                else break;
            }
            return stParameters;
        }

        public string get(string strkey)
        {
            int intColumn;
            string strValue = null;
            // Loop through each item for the parameter 
            for (intColumn = 0; intColumn <100; intColumn++)
            {
                // get current item of name 
                string strTempKey = parameters[0,intColumn];
                if (strTempKey.Trim().ToLower().Equals(strkey.Trim().ToLower()))
                {
                    strValue = parameters[1,intColumn];
                    break;
                }
            }
            return strValue;
        }

        private string getItem(int intColumn)
        {
            string strItemDetail = null;
            string strTempKey = parameters[0, intColumn];
            if (strTempKey != null)
            {
                strItemDetail = strTempKey + ":" + parameters[1, intColumn];
            }
            return strItemDetail;
        }

        public string getNextItem(int intColumn)
        {
            string strItemDetail = null;
            string strTempKey = parameters[0, intColumn];
            if (strTempKey != null)
            {
                strItemDetail = strTempKey + "/" + parameters[1, intColumn];
            }
            return strItemDetail;
        }

        public Boolean isSet()
        {
            if (getItem(0) != null) return true;
            else return false;
        }
    }
}
